import { ref } from 'vue'
import { getSapCallLogList as getSapCallLogListApi } from '@/api/basic'

/**
 * SAP调用日志列表服务
 */
export default function () {
  const getSapCallLogListLoading = ref(false)
  const getSapCallLogListParam = ref({
    page: 1,
    size: 50,
  })
  const total = ref(0)
  const sapCallLogList = ref<Array<{ id: string; record: string; date: string }>>([])

  const getSapCallLogList = async () => {
    getSapCallLogListLoading.value = true
    const res = await getSapCallLogListApi(
      getSapCallLogListParam.value.page,
      getSapCallLogListParam.value.size,
    )
    if (res.data.code === 20000) {
      total.value = Number(res.data.data.row.total)
      sapCallLogList.value = res.data.data.row.rows
    }
    getSapCallLogListLoading.value = false
  }

  return {
    total,
    sapCallLogList,
    getSapCallLogListParam,
    getSapCallLogListLoading,
    getSapCallLogList,
  }
}
